#pragma  once

#include "BasicType.h"
#include "Stream.h"
#include "CharacterList.h"
#include "SceneObject.h"
#include "ActionRecord.h"
#include "As2Variable.h"


namespace LightPlayer {

	class DisplayList;
	class SceneObject;
	class LightAbstractRenderer;
	class As2VM;

	enum PropertyEnum{
		_X = 0, _Y, _xscale, _yscale, _currentframe, _totalframes, _alpha, _visible, _width, _height, _rotation,
		_target, _framesloaded, _name, _droptarget, _url, _highquality, _focusrect, _soundbuftime, _quality, _xmouse, _ymouse
	};

	class Parser{
	public:
		virtual Stream*								getParserStream() = 0;
		virtual CharacterList*						getCharacterList() = 0;
		virtual pool<SceneObject>*					getObjectPool() = 0;
		virtual pool<TimelineObject>*				getTimelineObjectPool() = 0;
		virtual DisplayList*						getDisplayList() = 0;
		virtual ActionList*							getActionList() = 0;
		virtual uint32								getFrameNumber() = 0;
		virtual uint32								getActualFrame() = 0;
		virtual void								setActualFrame(uint32 frame) = 0;
		virtual SceneObject*						getNewSceneObject() = 0;
		virtual TimelineObject*						getNewTimelineObject() = 0;
		virtual void								freeObject(SceneObject* object) = 0;
		virtual uint16								getFrameForLabel(const char* label) = 0;
		virtual As2VM*								getAs2VM() = 0;
		virtual Parser*								getParent() {return NULL;};
		virtual Parser*								getRoot();
	protected:
		// as2 function
		virtual bool								isPlaying() const = 0;
		virtual void								play() = 0;
		virtual void								stop() = 0;
		virtual As2Var								getVar(const char* name) = 0;
		virtual void								setVar( const char* name, const As2Var& value ) = 0;
		virtual As2Var								getProperty( PropertyEnum property ) = 0;
		virtual void								setProperty(PropertyEnum property, const As2Var& value ) = 0;
		virtual void								gotoFrame(uint16 frame);
		virtual bool								gotoLabel(const char* label);

		// none NEEDED getter for parser
		virtual LightAbstractRenderer*				getRenderer() {return NULL;}
		// implementation 

		void	firstUpdate();
		void	update(float dt);
		Parser* getTargetObjectAtName(const char * Name);
		Parser* getTargetObjectAtPath(const char * Path);
		bool	isStrContainTarget(const char * Str);
		void	doActionList();

		void rewind();
		void ParseNextFrame();
		// Display List Tag
		bool Parse_DisplayListTags( const TAG& tag );
			bool Parse_PlaceObject( const TAG& tag ); 
			bool Parse_PlaceObject2( const TAG& tag ); 
			bool Parse_RemoveObject( const TAG& tag );
		// Control Tag
		bool Parse_ControlTags( const TAG& tag );
		// Define Tag
		bool Parse_DefineTags( const TAG& tag );
			bool Parse_DefineShape( const TAG& tag ); 
			bool Parse_DefineSprite( const TAG& tag ); 
			bool Parse_DefineBitmap( const TAG& tag ); 
			bool Parse_DefineFont( const TAG& tag ); 
			bool Parse_DefineFontInfo( const TAG& tag ); 
			bool Parse_DefineText1( const TAG& tag ); 
		// Action Tag
		bool Parse_ActionTags( const TAG& tag );
			bool Parse_DoAction( const TAG& tag ); 
		// not supported yet !
		bool Parse_UnsupportedTags( const TAG& tag );

	public:
		virtual ~Parser(){};
	};

};